package com.eva.client.api.cms;

import com.eva.cms.biz.article.CmsArticleBiz;
import com.eva.cms.biz.article.dto.QueryCmsArticleDTO;
import com.eva.cms.biz.article.vo.CmsArticleProfileVO;
import com.eva.constants.CmsArticleStatusEnum;
import com.eva.framework.common.api.BaseController;
import com.eva.framework.common.model.ApiResponse;
import com.eva.framework.common.model.PageData;
import com.eva.framework.common.model.PageWrap;
import com.eva.service.cms.vo.CmsArticleDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "文章相关接口")
@RestController
@RequestMapping("/article")
public class CmsArticleController extends BaseController {

    @Resource
    private CmsArticleBiz cmsArticleBiz;

    @ApiOperation("分页查询文章简要信息")
    @PostMapping("/profile/page")
    public ApiResponse<PageData<CmsArticleProfileVO>> findProfilePage(@RequestBody PageWrap<QueryCmsArticleDTO> pageWrap) {
        pageWrap.getModel().setStatus(CmsArticleStatusEnum.ONLINE.name());
        return ApiResponse.success(cmsArticleBiz.findProfilePage(pageWrap));
    }

    @ApiOperation("查询文章详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleUid", value = "文章唯一标识", dataType = "String", required = true),
            @ApiImplicitParam(name = "mode", value = "模式（preview预览模式）", dataType = "String")
    })
    @GetMapping("/{articleUid}")
    public ApiResponse<CmsArticleDetailVO> findDetail (@PathVariable String articleUid, @RequestParam String mode) {
        return ApiResponse.success(cmsArticleBiz.detail(articleUid, mode));
    }
}
